import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
import Login from '../views/Login.vue'
import AddUser from '../views/AddUser.vue'
import AddSite from '../views/AddSite.vue'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/login',
    name: 'Login',
    component: Login
  },
  {
    path: '/adduser',
    name: 'AddUser',
    component: AddUser
  },
  {
    path: '/addsite',
    name: 'AddSite',
    component: AddSite
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  }
]


const router = createRouter({
  base: "/autocard/", // 生产环境
  history: createWebHistory(process.env.BASE_URL),
  routes
})

// 注册一个全局前置守卫
// router.beforeEach((to,from,next) => {
//   if(to.name !== 'Login' && !localStorage.getItem('uid')) {
//     next({name:'Login'})
//   } else {
//     next() // 放行
//   }
// })

export default router
